package org.yangspring.samples.mvc.daoOracle;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.yangspring.samples.mvc.domainOracle.ProductDesc;

import java.util.List;

/**
 * Created by whyang on 2017/06/22.
 */

@Repository
public class ProductDescDAOImpl implements ProductDescDAO {

    private static final Logger logger = LoggerFactory.getLogger(ProductDescDAO.class);

    @Autowired
    @Qualifier("hibernate5AnnotatedSessionFactoryOracle")
    private SessionFactory sessionFactory;
    /*public void setSessionFactory(SessionFactory sessionFactory){
        this.sessionFactory = sessionFactory;
    }*/


    public List<ProductDesc> listProdDesc(){
//        Session session = this.sessionFactory.getCurrentSession();
        Session session = this.sessionFactory.openSession();
        TransactionSynchronizationManager.bindResource(this.sessionFactory, session);

        List<ProductDesc> prodDescList = session.createQuery("from ProductDesc").list();

        for(ProductDesc e : prodDescList){
            logger.info("prodDesc List::" + e);
        }
        return prodDescList;
    }

}
